/**
 * 
 */
package nullby.omnia.ui;

import java.util.List;

import nullby.omnia.ApplicationOmnia;
import nullby.omnia.R;
import nullby.omnia.db.DatabaseHelper;
import nullby.omnia.model.Theme;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout;

import com.actionbarsherlock.internal.widget.IcsSpinner;

/**
 * @author Sergey Bandysik (bandysik[at]gmail[dot]com)
 * 
 */
public class SpinnerTheme extends RelativeLayout {
	private IcsSpinner spinner;

	private List<Theme> langList;

	private ArrayAdapter<Theme> adapter;

	/**
	 * @param context
	 */
	public SpinnerTheme(Context context) {
		super(context);
		initComponents(context);
	}

	public SpinnerTheme(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initComponents(context);
	}

	public SpinnerTheme(Context context, AttributeSet attrs) {
		super(context, attrs);
		initComponents(context);
	}

	private void initComponents(Context context) {
		LayoutInflater.from(context).inflate(R.layout.view_spinner_theme, this,
				true);

		spinner = (IcsSpinner) findViewById(R.id.spinner);

		langList = DatabaseHelper.get().getListTheme(
				DatabaseHelper.EXPLORATION, ApplicationOmnia.userId,
				ApplicationOmnia.translationId);

		adapter = new ArrayAdapter<Theme>(getContext(),
				R.layout.sherlock_spinner_item, langList);
		adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

		spinner.setAdapter(adapter);
	}

}
